﻿using System;
using System.Web;
using System.Web.UI;
using Navigant.Infrastructure.Helpers;
using Navigant.Infrastructure.UrlDictionary;

namespace Navigant.Web
{
    public partial class Redir : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get the key from the querystring
            string key = Request.QueryString["key"];

            // Get the value
            string redir = string.Empty;
            try
            {
                redir = UrlDictionaryService.GetFullUrl(key);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                Response.Write("There was a system error redirecting the acknowledgement.  Please try again later.");
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }

            // No value was found, bad key
            if (string.IsNullOrEmpty(redir))
            {
                this.Response.Write("Provided key was not found in the dictionary.");
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            else
            {
                this.Response.Redirect(redir, false);
            }
        }
    }
}
